package com.adeoservices.gwt.dispatch.spring.sample.server.allowed;

import net.customware.gwt.dispatch.server.ActionHandlerRegistry;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.adeoservices.gwt.dispatch.spring.sample.client.allowed.AllowedAction;
import com.adeoservices.gwt.dispatch.spring.sample.client.allowed.AllowedResult;
import com.adeoservices.gwt.dispatch.spring.sample.server.business.MyBusinessService;
import com.adeoservices.gwt.dispatch.spring.server.handler.SpringActionHandler;

@Component
public class AllowedActionHandler extends SpringActionHandler<AllowedAction, AllowedResult>{

	@Autowired
	private MyBusinessService myBusinessService;
	
	@Autowired
	public AllowedActionHandler(ActionHandlerRegistry actionHandlerRegistry) {
		super(actionHandlerRegistry);
	}

	public AllowedResult execute(AllowedAction action, ExecutionContext context)
			throws ActionException {
		
		// do what you have to do
		myBusinessService.printHello();
		
		return new AllowedResult();
	}

	public Class<AllowedAction> getActionType() {
		return AllowedAction.class;
	}

	public void rollback(AllowedAction action, AllowedResult result,
			ExecutionContext context) throws ActionException {
	}

}
